<template>
  <router-link
    :to="{ path: '/course/detail', query: { id: item.id } }"
    class="cursor-item"
    v-for="item in data"
    :key="item.id"
  >
    <img :src="item.courseLogo" />
    <h3>{{ item.categoryName }}</h3>
    <div class="flex-yc man" v-if="item.lecturer">
      <img :src="item.lecturer.lecturerHead" />
      <span class="name">{{ item.lecturer.lecturerName }}</span>
      <span>{{ item.lecturer.lecturerPosition }}</span>
      <span>{{ item.lecturer.countCourse }}节课</span>
    </div>
    <div class="flex-yc flex-xbt">
      <span class="flex-yc">
        <el-icon class="el-icon--left"><Avatar /></el-icon>
        {{ item.countStudy }}人正在学习
      </span>
      <b>
        <span>¥</span>
        {{ item.coursePrice }}
      </b>
    </div>
  </router-link>
</template>

<script setup lang="ts">
import { respCourseData } from '@/pages/course/api/types/course'

withDefaults(
  defineProps<{
    data?: respCourseData[]
  }>(),
  { data: [] },
)
</script>

<style scoped lang="scss">
.cursor-item {
  width: 410px;
  margin-right: 35px;
  margin-bottom: 47px;
  background-color: #fff;

  &:nth-child(3n) {
    margin-right: 0;
  }

  &:hover {
    box-shadow: rgb(0 0 0 / 10%) 0 0 36px;
  }

  > img {
    width: 410px;
    height: 230px;
    background-color: #eee;
  }

  h3 {
    width: 100%;
    padding: 20px 20px 12px;
    overflow: hidden; /* 溢出部分隐藏 */
    font-size: 18px;
    font-weight: 500 !important;
    color: #333;
    text-overflow: ellipsis; /* 显示省略号 */
    white-space: nowrap; /* 不换行 */
  }

  > .flex-yc.flex-xbt {
    padding: 10px 20px 16px;
    font-size: 14px;
    color: #8691a3;

    b {
      font-size: 24px;
      color: #ea3553;

      span {
        font-size: 14px;
      }
    }
  }

  .flex-yc.man {
    padding: 0 20px;

    > img {
      width: 24px;
      height: 24px;
      background-color: #eee;
      border-radius: 50%;
    }

    > span {
      padding: 0 20px;
      font-size: 14px;
      color: #8691a3;

      &.name {
        font-weight: bold;
        color: #021429;
      }

      & + span {
        border-left: 1px solid #d9d9d9;
      }
    }
  }
}
</style>
